package io.itit.ecp.admin.provide.filter;

import com.alibaba.fastjson.serializer.ValueFilter;
import io.itit.grass.common.server.helper.DictHelper;
import io.itit.grass.common.utils.CommonUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;

/**
 * <p>
 *
 * @Author：Roy
 * @Description：能源类型键值转换
 * @Date：Create by 2023-11-23 16:12:43
 */
public interface IEnergyTypeFilter {

	String STATUS = "status" ;

	String ENERGY_TYPE_STATUS = "ecp-admin.energyType.status" ;

	class EnergyTypeExportFilter implements ValueFilter {

		private Map<Integer, String> statusMap;

		public EnergyTypeExportFilter() {
			statusMap = DictHelper.i().integerVlMap(ENERGY_TYPE_STATUS);
		}

		@Override
		public Object process(Object object, String name, Object value) {
			if (StringUtils.equals(name, STATUS)) {
				return CommonUtils.orElse(statusMap.get(CommonUtils.toInteger(value)), value);
			}
			return value;
		}

	}

	class EnergyTypeUploadFilter implements ValueFilter {

		private Map<String, Integer> statusMap;

		public EnergyTypeUploadFilter() {
			statusMap = DictHelper.i().integerLvMap(ENERGY_TYPE_STATUS);
		}

		@Override
		public Object process(Object object, String name, Object value) {
			if (StringUtils.equals(name, STATUS)) {
				return CommonUtils.orElse(statusMap.get(CommonUtils.toString(value)), value);
			}
			return value;
		}

	}

}
